package com.pqy.ts.entity.vo;

import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author panqiyi
 * @date 2022/6/5 - 21:03
 */
@Data
public class R implements Serializable {
    private static final String SUCCESS = "20000";
    private static final String ERROR = "20001";

    private Boolean success;
    private String code;
    private String message;
    private Map<String,Object> data = new HashMap<>();
   // private List<Object> dadaList = new ArrayList<>();

    public static R ok(){
        R r = new R();
        r.setSuccess(true);
        r.setCode(SUCCESS);
        r.setMessage("成功");
        return r;
    }

    public static R error(){
        R r = new R();
        r.setSuccess(false);
        r.setCode(ERROR);
        r.setMessage("失败");
        return r;
    }

    public R success(Boolean success){
        this.setSuccess(success);
        return this;
    }

    public R message(String message){
        this.setMessage(message);
        return this;
    }

    public R code(String code){
        this.setCode(code);
        return this;
    }

    public R data(String key, Object value){
        this.data.put(key, value);
        return this;
    }

    public R data(Map<String, Object> map){
        this.setData(map);
        return this;
    }
   /* public R dataList(List list){
        this.setDadaList(list);
        return this;
    }*/
}
